package com.suse.jd_system_server.utils;

import com.suse.jd_system_server.entity.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;


public class SecurityUser implements UserDetails {

    private final User user;
    private List<SimpleGrantedAuthority> authorities;

    public SecurityUser(User user){
        this.user=user;
    }

    public void setAuthorities(List<SimpleGrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    public User getUser() {
        return user;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {//配置权限
//        GrantedAuthority grantedAuthority = new GrantedAuthority() {
//            @Override
//            public String getAuthority() {
//                return null;
//            }
//        };
//        List<GrantedAuthority> list = new ArrayList<>();
//        list.add(grantedAuthority);
        return authorities;
    }

    @Override
    public String getPassword() {//获取用户密码
        return user.getPassword();
    }

    @Override
    public String getUsername() {//获取用户名
        return user.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {//返回用户账户是否过期
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {//返回账户是否已锁定
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {//返回凭据/密码是否过期
        return true;
    }

    @Override
    public boolean isEnabled() {//
        return true;
    }
}

